$(function () {
    getServiceTypeFindAll();
    let id = localStorage.getItem("orderId");
    findById(id);
});

function getServiceTypeFindAll() {
    $.ajax({
        url: '/back/serviceType/findType',
        data: '',
        dataType: 'json',
        type: 'get',
        success: function (data) {
            data = data.list;
            let html = "";
            for (let i = 0; i < data.length; i++) {
                html += '<option value="' + data[i].id + '">' + data[i].serviceType + '</option>';
            }
            $("#roomType").html(html);//将页面格式加载到页面布局
        }

    })
}

function findById(id) {
    $.ajax({
        url: '/back/order/findById',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (data) {
            showOrder(data.orderModel);
        }
    })
}

function showOrder(data) {
    $("#orderId").val(data.id);
    $("#username").val(data.username);
    $("input[name='sex'][value='" + data.sex + "']").attr("checked", true);
    $("#phone").val(data.phone);
    $("#roomType option[text='"+data.roomType+"']").attr("selected", true);
    $("input[name='channel'][value='" + data.channel + "']").attr("checked", true);
    $("#reservationTime").val(data.reservationTime);
    $("#checkInTime").val(data.checkInTime);
    $("#checkOutTime").val(data.checkOutTime);
}

function orderEdit() {
    var data = {};
    data.id=$("#orderId").val();
    data.username = $("#username").val();
    data.sex = $("input[name='sex']:checked").val();
    data.phone = $("#phone").val();
    data.roomType = $("#roomType").find("option:selected").text();
    data.channel = $("input[name='channel']:checked").val();
    data.reservationTime = $("#reservationTime").val();
    data.checkInTime = $("#checkInTime").val();
    data.checkOutTime = $("#checkOutTime").val();
    $.ajax({
        url: '/back/order/orderEdit',
        data: data,
        type: 'get',
        dataType: 'json',
        success: function (data) {
            if (data.result === 1) {
                alert("修改成功!")
                $("#right").load('/back/order/orderManage.html');
            }else {
                alert("修改失败！")
            }
        }
    })
}

function cancelOreder() {
    $("#right").load('/back/order/orderManage.html');
}